using System;
using System.Collections.Generic;
using System.Text;

using System.Threading;
using System.Xml;
using System.ServiceModel;

using System.ServiceModel.Channels;
using System.IO;
using Spike.ContractBuilder;

namespace Spike.TestHarness
{
    public delegate void TestResultCallback(TestCaseResult.STATUS status);

    public class TestThread
    {

        // Delegate used to execute the callback method when the
        // task is complete.
        private TestResultCallback callback;
        TestCase test = null;
        TestCaseResult result = null;

        public TestThread(TestCase test, TestCaseResult result, TestResultCallback callback)
        {
            this.callback = callback;
            this.test = test;
            this.result = result;
        }

        public void RunTest()
        {
            DateTime start = DateTime.Now;

            try
            {
                result.Status = TestCaseResult.STATUS.Running;
                
                result.Output = ContractGenerator.Instance.InvokeProxyMethod(test);
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }

            TimeSpan elapsed = DateTime.Now.Subtract(start);
            result.ElapsedTime = elapsed.TotalSeconds;

            this.callback(result.Status);
        }
    }
}
